/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain;

import Server.domain.BomberManGameServer;
import Server.domain.threads.BomberManGameServerThread;

/**
 *
 * @author user
 */
public class BomberManGame extends Thread
{
	//the server class
	private  BomberManGameServerThread gameThread;
        private BomberManGameServer server;
        
	
	//frames per second counter variables
	long prevTime = System.currentTimeMillis();
	float elapsedTime = 0;
	int prevSec = 0;
	int fps = 0;
	int frameCount = 0;
	
	//game flag
	boolean gameRunning = true;
	
	//player list
	PlayerList playerList = new PlayerList();
	
	public BomberManGame(BomberManGameServer server, String name)
	{
		super(name);
                this.server = server;
		gameThread = new BomberManGameServerThread(server);
		gameThread.start();
	}
	public void run()
	{
		while(gameRunning)
		{
			//all game related code can go here//
			
			//move all players
			playerList.advance(elapsedTime);
			
			calcElapsedTime();
			try
			{
				Thread.sleep(10);
			}
			catch (InterruptedException e)
			{
				e.printStackTrace();
				gameRunning = false;
			}
		}
	}
	public void calcElapsedTime()
	{
		elapsedTime = (float)(System.currentTimeMillis() - prevTime);
		prevTime = System.currentTimeMillis();
		if(prevSec != (int)(System.currentTimeMillis()/1000))
		{
			fps = frameCount;
			frameCount = 0;
		}
		frameCount++;
		prevSec = (int)(System.currentTimeMillis()/1000);
	}
}
